package cn.pku.ss.sirx.sna.ib.util;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import cn.pku.ss.sirx.sna.ib.bean.Message;

/**
 * A utility class.
 *
 * @author SirX
 * @version 1.0
 */
public class Util {
    
    public static Message getMessage(String fromId, String toId, String content, Date time, boolean isNewReply) {
        Message message = new Message();
        message.setFromId(fromId);
        message.setToId(toId);
        message.setContent(content);
        message.setTime(time);
        message.setNewReply(isNewReply);
        return message;
    }

    /**
     * Filter the hour, minute, second and milisecond part of a date.
     * @param date a date to filter
     * @return a filtered date
     */
    public static Date filterTime(Date date) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }
    
}
